<template>
  <base-layout
    :dialog-title="dialogTitle"
    :dialog-visible="dialogVisible"
    dialog-width="1100px"
    :page-show="pageShow"
    @dialog-close="dialogClose"
  >
    <template #toolPanel >
      <!--编辑界面-->
      <el-dialog title="编辑供货商产品" width="700px" :visible.sync="editFormVisible" :close-on-click-modal="false">
        <el-form :model="editForm" label-width="100px"  :inline="true" ref="editForm">
          <el-form-item label="运营商" prop="operatoruid"  >
            <el-select v-model="editForm.operatoruid" filterable clearable placeholder="请选择运营商"  >
              <el-option
                v-for="item in operator"
                :key="item.operatoruid"
                :label="item.operatorname"
                :value="item.operatoruid">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="省份" prop="provinceuuid"  >
            <el-select v-model="editForm.provinceuuid" filterable clearable @change="selectCity(editForm.provinceuuid)" placeholder="请选择省份" >
              <el-option
                v-for="item in info"
                :key="item.provinceuuid"
                :label="item.provincename"
                :value="item.provinceuuid">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="城市">
            <el-select v-model="editForm.cityName" filterable clearable placeholder="请选择地市">
              <el-option
                v-for="item in citys"
                :key="item.cityName"
                :label="item.cityName"
                :value="item.cityName">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="业务类型" prop="busuuid"  >
            <el-select v-model="editForm.busuuid" filterable clearable placeholder="请选择业务类型"   >
              <el-option
                v-for="item in bus"
                :key="item.busuuid"
                :label="item.busname"
                :value="item.busuuid">
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="供货商" prop="useruuid" >
            <el-select v-model="editForm.useruuid" filterable clearable placeholder="请选择供货商"   >
              <el-option
                v-for="item in usersUp"
                :key="item.user.useruuid"
                :label="item.user.username"
                :value="item.user.useruuid">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="产品名称" prop="productName">
            <el-input v-model="editForm.productName" clearable placeholder="请输入产品名称"></el-input>
          </el-form-item>
          <el-form-item label="产品编码" prop="productCode" >
            <el-input v-model="editForm.productCode" clearable placeholder="请输入产品编码"></el-input>
          </el-form-item>
          <el-form-item label="原价" prop="price">
            <el-input v-model="editForm.price" clearable v-on:input="discountChangeEdit"></el-input>
          </el-form-item>
          <el-form-item label="面值"  prop="upfacevalue">
            <el-input v-model="editForm.upfacevalue" clearable placeholder="如 1024 表示 1024M流量"  ></el-input>
          </el-form-item>
          <el-form-item label="折扣"  prop="discount">
            <el-input v-model="editForm.discount" clearable  v-on:input="discountChangeEdit"  ></el-input>
          </el-form-item>
          <el-form-item label="折扣金额" prop="discount">
            <el-input v-model="editForm.discountAmount" clearable :disabled="true"></el-input>
          </el-form-item>
          <!--				<el-form-item label="有效期" prop="validity">-->
          <!--					<el-select v-model="editForm.validity" placeholder="请选择运有效期">-->
          <!--						<el-option value="0" label="全部">全部</el-option>-->
          <!--						<el-option value="1" label="30天">30天</el-option>-->
          <!--						<el-option value="2" label="当月">当月</el-option>-->
          <!--					</el-select>-->
          <!--				</el-form-item>-->

          <el-form-item label="备注">
            <el-input clearable v-model="editForm.remark"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer" style="text-align: center;">
          <el-button size="small" round @click.native="editFormVisible = false">取消</el-button>
          <el-button size="small" round type="primary" @click.native="editSubmit" >提交</el-button>
        </div>
      </el-dialog>

      <el-dialog title="批量编辑供货商产品" :visible.sync="batchFormVisible" :close-on-click-modal="false">
        <el-form :model="batchForm" label-width="100px" :inline="true" ref="batchForm">
          <el-form-item label="运营商" prop="operatoruid"  >
            <el-select v-model="batchForm.operatoruid" filterable @change="changeOperator" placeholder="请选择运营商"    >
              <el-option
                v-for="item in operator"
                :key="item.operatoruid"
                :label="item.operatorname"
                :value="item.operatoruid">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="省份" prop="provinceuuid"  >
            <el-select v-model="batchForm.provinceuuid" filterable  @change="selectCity(batchForm.provinceuuid)" placeholder="请选择省份" >
              <el-option
                v-for="item in info"
                :key="item.provinceuuid"
                :label="item.provincename"
                :value="item.provinceuuid">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="城市">
            <el-select v-model="batchForm.cityName" filterable clearable placeholder="请选择地市">
              <el-option
                v-for="item in citys"
                :key="item.cityName"
                :label="item.cityName"
                :value="item.cityName">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="业务类型" prop="busuuid"  >
            <el-select v-model="batchForm.busuuid" filterable placeholder="请选择业务类型" @change="handleBatchCheckedChange"  >
              <el-option
                v-for="item in bus"
                :key="item.busuuid"
                :label="item.busname"
                :value="item.busuuid">
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="供货商" prop="useruuid" >
            <el-select v-model="batchForm.useruuid" filterable placeholder="请选择供货商"   >
              <el-option
                v-for="item in usersUp"
                :key="item.user.useruuid"
                :label="item.user.username"
                :value="item.user.useruuid">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="折扣"  prop="unitPrice">
            <el-input v-model="batchForm.unitPrice" style="width: 198px;" v-on:input="discountBatchChangeAdd"></el-input>
          </el-form-item>
          <!--				<el-form-item label="流量类型" label-width="120px">-->
          <!--					<el-radio-group v-model="batchForm.packagetype">-->
          <!--						<el-radio  :label="1">流量池</el-radio>-->
          <!--						<el-radio  :label="0">包型</el-radio>-->
          <!--					</el-radio-group>-->
          <!--				</el-form-item>-->
          <el-form-item label="权益包型" prop="channe">
            <el-checkbox-group v-model="batchForm.channe" @change="handleBatchCheckedChange">
              <el-checkbox v-for="channel in channels" :label="channel.basePrice" :key="channel.baseId">{{channel.baseName}}</el-checkbox>
            </el-checkbox-group>
          </el-form-item>

          <!--				<el-form-item label="折扣"  prop="unitPrice">-->
          <!--					<el-input v-model="batchForm.unitPrice" v-on:input="discountBatchChangeAdd"></el-input>-->
          <!--				</el-form-item>-->

          <el-row>
            <el-col :span="24">
              <el-form-item label="压单" >
                <el-switch
                  v-model="batchForm.pressOrder"
                  @change="changeBatchPressOrder(batchForm)"
                  active-text=""
                  inactive-text="">
                </el-switch>
              </el-form-item>

              <el-form-item label="人工" >
                <el-switch
                  v-model="batchForm.artificial"
                  active-text="" @change="changeBatchArtificial(batchForm)"
                  inactive-text="">
                </el-switch>
              </el-form-item>
            </el-col>
          </el-row>

          <el-table :data="setBatchProducts"  show-overflow-tooltip="true" max-height="620"  border style="width: 100%;">
            <el-table-column type="index" width="80" label="编号">
            </el-table-column>
            <el-table-column prop="productName" label="产品名称" show-overflow-tooltip width="130px" :formatter="updateProductName(batchForm)">
            </el-table-column>
            <el-table-column prop="productCode"  width="210px" label="产品编码" show-overflow-tooltip   >
              <template  scope="scope">
                <el-input v-model="scope.row.productCode"></el-input>
              </template>
            </el-table-column>
            <el-table-column prop="upfacevalue"  width="100px" label="面值" :formatter="upfacevalueProductBatch" >
            </el-table-column>
            <el-table-column prop="price"  width="110px" label="原价" :formatter="upfacevalueprice">
            </el-table-column>
            <el-table-column prop="discount"  width="100px" label="折扣">
            </el-table-column>
            <el-table-column prop="discountAmount"  label="成本金额">
            </el-table-column>
          </el-table>
        </el-form>
        <div slot="footer" class="dialog-footer" style="text-align: center;">
          <el-button size="small" round @click.native="batchFormVisible = false">取消</el-button>
          <el-button type="primary" size="small" round @click.native="editBatchUpProduct" >提交</el-button>
        </div>
      </el-dialog>

      <el-dialog title="定时调价" size="big" width="1200px" :visible.sync="matchFormBatchLoading" :close-on-click-modal="false">
        <el-form :model="matchBatchForm" :inline="true" label-width="100px" ref="matchBatchForm">
          <el-form-item label="运营商" prop="operatoruid">
            <el-select v-model="matchBatchForm.operatoruid" placeholder="请选择运营商">
              <el-option value="0" label="全部">全部</el-option>
              <el-option
                v-for="item in operator"
                :key="item.operatoruid"
                :label="item.operatorname"
                :value="item.operatoruid">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="省份" prop="provinceuuid">
            <el-select v-model="matchBatchForm.provinceuuid" @change="selectCity(matchBatchForm.provinceuuid)" placeholder="请选择省份">
              <el-option value="0" label="全部">全部</el-option>
              <el-option
                v-for="item in info"
                :key="item.provinceuuid"
                :label="item.provincename"
                :value="item.provinceuuid">
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="地市"  >
            <el-select v-model="matchBatchForm.cityName"  clearable placeholder="请选择地市">
              <el-option
                v-for="item in citysMatchs"
                :key="item.cityName"
                :label="item.cityName"
                :value="item.cityName">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="业务类型" prop="busuuid">
            <el-select v-model="matchBatchForm.busuuid" placeholder="请选择业务类型">
              <el-option value="0" label="全部">全部</el-option>
              <el-option
                v-for="item in bus"
                :key="item.busuuid"
                :label="item.busname"
                :value="item.busuuid">
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="供货商" prop="useruuid">
            <el-select v-model="matchBatchForm.useruuid"   clearable filterable   placeholder="请选择供货商">
              <el-option
                v-for="item in usersUp"
                :key="item.user.useruuid"
                :label="item.user.username"
                :value="item.user.useruuid">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="面值">
            <el-select v-model="matchBatchForm.upfacevalue" clearable filterable collapse-tags multiple placeholder="请面值">
              <el-option value="0" label="全部">全部</el-option>
              <el-option
                v-for="item in downfacevalues"
                :key="item.id"
                :label="item.id"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" size="small" round v-on:click="upProductBatch">查询</el-button>
          </el-form-item>
          <el-row style="color: red;margin-bottom: 10px;">
            <el-form-item label="注意">请选择执行时间点</el-form-item>
            <el-form-item label="调价前折扣">
              <el-input v-model="matchBatchForm.beforediscount" style="width: 95px;" clearable placeholder="折扣"></el-input>
            </el-form-item>
            <el-form-item label="调价后折扣">
              <el-input v-model="matchBatchForm.afterdiscount" style="width: 95px;" v-on:input="batchTimerPriceInput" clearable placeholder="折扣"></el-input>
            </el-form-item>
            <el-form-item label="执行时间">
              <el-date-picker type="datetime" placeholder="开始时间" format="yyyy-MM-dd HH:mm:ss"   v-model="matchBatchForm.executeTime" style="width: 100%;"></el-date-picker>
            </el-form-item>
            <el-form-item label="备注">
              <el-input  type="datetime" placeholder="备注" format="yyyy-MM-dd HH:mm:ss" :maxlength="100"  v-model="matchBatchForm.note" style="width: 100%;"></el-input>
            </el-form-item>
          </el-row>
          <!--列表-->
          <el-table :data="upproductsBatch" highlight-current-row max-height="470" border
                    ref="multipleTableBatchTimer" show-overflow-tooltip="true" style="width: 100%"
                    @selection-change="handleSelectionChangeBatchTimer" >
            <el-table-column type="selection"   >
            </el-table-column>
            <el-table-column type="index" width="50" label="编号">
            </el-table-column>
            <el-table-column prop="operators.operatorname" show-overflow-tooltip width="80px" label="运营商">
            </el-table-column>
            <el-table-column prop="provincialInformation.provincename" show-overflow-tooltip width="50px" label="省份">
            </el-table-column>
            <el-table-column prop="businessType.busname"  show-overflow-tooltip width="80px" label="业务类型">
            </el-table-column>
            <el-table-column prop="user.username" width="100px" show-overflow-tooltip label="分销商">
            </el-table-column>
            <el-table-column prop="productCode" show-overflow-tooltip  label="产品编码">
            </el-table-column>
            <el-table-column prop="productName" show-overflow-tooltip  width="110px" label="产品名称">
            </el-table-column>
            <el-table-column prop="price"  width="100px" label="原价" show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="upfacevalue" label="面值"  width="90px" show-overflow-tooltip  :formatter="productType">
            </el-table-column>
            <el-table-column prop="discount"   width="90px" show-overflow-tooltip label="实际折扣">
            </el-table-column>
            <el-table-column prop="discountAmount" width="90px" label="实际金额" show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="status" label="状态" width="60px" :formatter="status">
            </el-table-column>
          </el-table>

          <!--工具条-->
          <el-pagination
            @current-change="handleCurrentChangeMatchBatchTimer"
            @size-change="handleSizeChangeMatchBatchTimer"
            layout="total,sizes,prev, pager, next"
            :page-size="pageSizeMatchBatchTimer"
            :total="totalMatchBatch">
          </el-pagination>
        </el-form>
        <div slot="footer" class="dialog-footer" style="text-align: center;">
          <el-button size="small" round @click.native="matchFormBatchLoading = false">取消</el-button>
          <el-button type="primary" size="small" round @click.native="saveBatchPrice" >保存调价</el-button>
        </div>
      </el-dialog>

    </template>
    <template #searchPanel>
      <search-panel :show-add-button="true" :show-search-button="true" @search="search" @exportData="exportUpProduct"
                    :showHandleBatchEdit="true" @timerPrice="timerPrice" :showTimerPrice="true"
                    :showExportDataButton="true" @insert="handleDataInsertBatch" @handleBatchEdit="handleBatchEdit" :left="true">
          <el-form-item label="运营商:">
            <el-select v-model="filters.operatoruid" filterable clearable  placeholder="请选择运营商">
              <el-option value="0" label="全部">全部</el-option>
              <el-option
                v-for="item in operator"
                :key="item.operatoruid"
                :label="item.operatorname"
                :value="item.operatoruid">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="省份:">
            <el-select v-model="filters.provinceuuid" filterable @change="selectfilter(filters.provinceuuid)" clearable placeholder="请选择省份">
              <el-option value="0" label="全部">全部</el-option>
              <el-option
                v-for="item in info"
                :key="item.provinceuuid"
                :label="item.provincename"
                :value="item.provinceuuid">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="地市:">
            <el-select v-model="filters.cityName" filterable clearable placeholder="请选择地市">
              <el-option
                v-for="item in infoFilters"
                :key="item.cityName"
                :label="item.cityName"
                :value="item.cityName">
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="业务类型:" prop="busuuid"  >
            <el-select v-model="filters.busuuid" filterable clearable placeholder="请选择业务类型"   >
              <el-option value="0" label="全部" >全部</el-option>
              <el-option
                v-for="item in bus"
                :key="item.busuuid"
                :label="item.busname"
                :value="item.busuuid">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="供货商:" prop="useruuid" >
            <el-select v-model="filters.useruuid" clearable placeholder="请选择供货商" filterable   >
              <el-option value="0" label="全部" >全部</el-option>
              <el-option v-if="usersUp && usersUp.length > 0"
                         v-for="item in usersUp"
                         :key="item.user.useruuid"
                         :label="item.user.username"
                         :value="item.user.useruuid">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="产品状态:" prop="validity">
            <el-select v-model="filters.status" clearable placeholder="请选择产品状态">
              <el-option value="" label="全部">全部</el-option>
              <el-option value="2" label="禁用">禁用</el-option>
              <el-option value="1" label="正常">正常</el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="产品编码:">
            <el-input v-model="filters.productCode" clearable placeholder="产品编码"></el-input>
          </el-form-item>
          <el-form-item label="面值:">
            <el-select v-model="filters.upfacevalue" clearable filterable collapse-tags multiple placeholder="请面值">
              <el-option value="0" label="全部">全部</el-option>
              <el-option
                v-for="item in downfacevalues"
                :key="item.id"
                :label="item.id"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
      </search-panel>
    </template>
    <template #contentPanel>
      <data-table
        :value="tableData"
        :total-count="totalCount"
        :has-action="true"
        :current="start"
        :isShowSelection="true"
        :table-column-attributes="tableColumnAttributes"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        @selection-change="selsChange"
        :width="230"
      >
        <template #action="{row}">
          <el-button size="small" round @click="editRow(row)">编辑</el-button>
          <el-button size="small" round @click="handleEnable(row)">{{row.status == 2 ? '启用' : '禁用'}}</el-button>
          <el-button size="small" round style="color:red;" @click="deleteEnable(row)">删除</el-button>
        </template>
      </data-table>
    </template>

    <template #dialog>
<!--      <el-dialog title="批量新增供货商产品" width="100%" v-model="dialogVisible" :close-on-click-modal="false">-->
        <el-form :model="form" label-width="100px" :inline="true" ref="form">
          <el-form-item label="运营商" prop="operatoruid"  >
            <el-select v-model="form.operatoruid" filterable @change="changeOperator" placeholder="请选择运营商"    >
              <el-option
                v-for="item in operator"
                :key="item.operatoruid"
                :label="item.operatorname"
                :value="item.operatoruid">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="省份" prop="provinceuuid"  >
            <el-select v-model="form.provinceuuid" filterable @change="selectCity(form.provinceuuid)" placeholder="请选择省份" >
              <el-option
                v-for="item in info"
                :key="item.provinceuuid"
                :label="item.provincename"
                :value="item.provinceuuid">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="城市">
            <el-select v-model="form.cityName" filterable clearable placeholder="请选择地市">
              <el-option
                v-for="item in citys"
                :key="item.cityName"
                :label="item.cityName"
                :value="item.cityName">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="业务类型" prop="busuuid"  >
            <el-select v-model="form.busuuid" filterable placeholder="请选择业务类型" @change="handleCheckedChange"  >
              <el-option
                v-for="item in bus"
                :key="item.busuuid"
                :label="item.busname"
                :value="item.busuuid">
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="供货商" prop="useruuid" >
            <el-select v-model="form.useruuid" filterable placeholder="请选择供货商"   >
              <el-option
                v-for="item in usersUp"
                :key="item.user.useruuid"
                :label="item.user.username"
                :value="item.user.useruuid">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="折扣"  prop="unitPrice">
            <el-input v-model="form.unitPrice" style="width: 197px;" v-on:input="discountChangeAdd"></el-input>
          </el-form-item>
          <el-form-item label="权益面值" prop="channe">
            <el-checkbox-group v-model="form.channe"   @change="handleCheckedChange">
              <el-checkbox v-for="channel in channels" :label="channel.basePrice" :key="channel.baseId">{{channel.baseName}}</el-checkbox>
            </el-checkbox-group>
          </el-form-item>

          <el-form-item label="压单" >
            <el-switch
              v-model="form.pressOrder"
              @change="changeBatchPressOrder(form)"
              active-text=""
              inactive-text="">
            </el-switch>
          </el-form-item>

          <el-form-item label="人工" >
            <el-switch
              v-model="form.artificial"
              active-text="" @change="changeBatchArtificial(form)"
              inactive-text="">
            </el-switch>
          </el-form-item>


          <el-table :data="setProducts"  show-overflow-tooltip="true" max-height="620" border style="width: 100%;">
            <el-table-column type="index" width="80" label="编号">
            </el-table-column>
            <el-table-column prop="productName"  label="产品名称" show-overflow-tooltip  width="130px">
            </el-table-column>
            <el-table-column prop="productCode" label="产品编码" >
              <template  scope="scope">
                <el-input v-model="scope.row.productCode"></el-input>
              </template>
            </el-table-column>
            <el-table-column prop="upfacevalue"  width="100px" label="面值" :formatter="upfacevalueProduct" >
            </el-table-column>
            <el-table-column prop="price"  width="110px" label="原价"   :formatter="upfacevalueprice">
            </el-table-column>
            <el-table-column prop="discount"  width="100px" label="折扣">
            </el-table-column>
            <el-table-column prop="discountAmount"  width="160px" label="成本金额">
            </el-table-column>
          </el-table>
        </el-form>
        <div slot="footer" class="dialog-footer"  style="text-align: center;">
          <el-button size="small" round @click.native="dialogVisible = false">取消</el-button>
          <el-button size="small" round type="primary" @click.native="addUpProduct" >提交</el-button>
        </div>
<!--      </el-dialog>-->
    </template>

  </base-layout>
</template>

<script>
import baseMixin from '@/mixins/base'
import {findOpeProBusShop,findAllUpShopInfo,findAllChannel,findAllCity,findByChannel} from '@/api/utilsapi'
import {findPageProduct,findOneUpProduct,exportUpProduct,productEnable,deleteUpProduct,addBatchUpProduct,updateUpProduct,
  findBatchUpProduct,editBatchUpProduct,batchProductTimerUp} from '@/api/upapi'
import util from "../../../utils/util";
import moment from "moment";

export default {
  name: 'upProduct',
  mixins: [
    baseMixin({
      idName: 'id',
      refresh: '',
      findData:findPageProduct,
      format(res) {
        return res.map(data => {
          return data
        })
      }
    })
  ],
  data() {
    return {
      pageShow: true,
      dialogData:{},
      tableColumnAttributes: [
        //运营商	省份	地市	业务类型	供货商	产品编码	产品名称	原价	面值	实际折扣 实际金额	状态	备注
        { name: '运营商', value: 'operatorname' ,formatter:this.operatornameFormatter , width: 76},
        { name: '省份', value: 'provincename' ,formatter:this.provincialInformationFormatter, width: 50 },
        { name: '地市', value: 'cityName' , width: 50},
        { name: '业务类型', value: 'busname' ,formatter:this.businessTypeFormatter , width: 80 },
        { name: '供货商', value: 'username',formatter:this.usernameFormatter },
        { name: '产品编码', value: 'productCode' },
        { name: '产品名称', value: 'productName' , width: 125 },
        { name: '原价', value: 'price' },
        { name: '面值', value: 'upfacevalue', width: 60 },
        { name: '实际折扣', value: 'discount' },
        { name: '实际金额', value: 'discountAmount' },
        { name: '状态', value: 'status',formatter:this.statusFormatter , width: 50},
        { name: '备注', value: 'remark' },
        { name: '创建时间', value: 'createtime', width: 150 },
      ],
      operator :[],
      info:[],
      bus:[],
      usersUp:[],
      ups:[],
      sels:[],
      infoFilters:[],
      downfacevalues:[],
      setBatchProducts:[],
      setBatchPhoneProducts:[],
      channels:[],
      setProducts:[],
      citys:[],
      filters: {
        provinceuuid:'',
        operatoruid:'',
        busuuid:'',
        useruuid:'',
        productCode:'',
        fastchargetype:'',
        upfacevalue:'',
        validity:'',
        cityName:'',
        status:''
      },
      form:{
        operatoruid: '',
        provinceuuid: '',
        busuuid: '',
        cityName:'',
        user: {useruuid:''},
        productCode: '',
        upfacevalue: '',
        discount: '1',
        fastchargetype: '1',
        remark: '',
        useruuid:'',
        upfailnum:1,
        uptimeinterva:1,
        price:'0',
        discountAmount:'',
        packagetype:1,
        unitPrice:"1",
        channe:[],
        pressOrder:false,
        artificial:false
      },
      batchForm: {
        operatoruid: '',
        cityName:'',
        provinceuuid: '',
        busuuid: '',
        user: {useruuid:''},
        productCode: '',
        upfacevalue: '',
        discount: '1',
        fastchargetype: '1',
        remark: '',
        useruuid:'',
        upfailnum:1,
        uptimeinterva:1,
        price:'0',
        discountAmount:'',
        packagetype:1,
        unitPrice:"1",
        channe:[],
        pressOrder:false,
        artificial:false
      },
      editFormVisible: false,//编辑界面是否显示
      //编辑界面数据
      editForm: {
        operatoruid: '',
        provinceuuid: '',
        cityName:'',
        busuuid: '',
        user: {useruuid:''},
        productCode: '',
        upfacevalue: '',
        discount: '',
        fastchargetype: '1',
        remark: '',
        useruuid:'',
        upfailnum:1,
        uptimeinterva:1,
        upprouuid:'',
        price:'0',
        discountAmount:'',
        validity:'1',
        productName:''
      },
      batchFormVisible:false,
      busstype :"4028b8815fcad58a015fcfc0d330001c",
      matchFormBatchLoading:false,
      matchBatchForm: {
        productCode: '',
        operatoruid: '',
        provinceuuid: '',
        busuuid: '',
        useruuid: [],
        upfacevalue:[],
        cityName:'',
        discount:0,
        beforediscount:0,
        afterdiscount:1,
        executeTime:moment().add('hour', 1).format('YYYY-MM-DD HH:mm:ss'),
        note:''
      },
      totalMatchBatch:0,
      pageSizeMatchBatchTimer: 100,
      startMatchBatchTimer:0,
      upproductsBatch:[],
      selsBatchTimer:[],
      //定时调价
      citysMatchs:[],
    }
  },
  methods: {
    async search(form){
      let para = {
        start: 0,
        pageSize: 10,
        provinceuuid:this.filters.provinceuuid == "0" ? "" :this.filters.provinceuuid ,
        operatoruid:this.filters.operatoruid == "0" ? "" :this.filters.operatoruid ,
        busuuid:this.filters.busuuid == "0" ? "" :this.filters.busuuid ,
        useruuid:this.filters.useruuid == "0" ? "" :this.filters.useruuid ,
        productCode:this.filters.productCode ,
        fastchargetype:'',
        upfacevalue:  (this.filters.upfacevalue == "0" || this.filters.upfacevalue.length == 0) ? "" : this.filters.upfacevalue,
        validity:this.filters.validity == "0" ? "" :this.filters.validity,
        cityName:this.filters.cityName,
        status: this.filters.status == "0" ? "" :this.filters.status
      };
      this.searchOptions = para;
      this.setTableData()
    },
    async findOpeProBusShop(){
      let para = {
        upprouuid:''
      };
      const result = await findOpeProBusShop(para);
      this.operator = result.data.operator;
      this.info = result.data.info;
      this.bus = result.data.bus;
    },
    async findAllUpShopInfo(){
      let para = {
        upprouuid:''
      };
      const result = await findAllUpShopInfo(para);
      this.usersUp = result.data;
    },
    async findAllChannel(){
      let para = {
        province : ""
      };
      const result = await findAllChannel(para);
      if(result && result.data){
        result.data.forEach(item =>{
          this.downfacevalues.push({id:item,value:item});
        });
      }
    },
    editRow (row) {
      this.editFormVisible = true;
      this.findAllCity(row.provincialInformation.provincename);
      let para = {
        upprouuid:row.upprouuid
      };
      findOneUpProduct(para).then(datas =>{
        let { message, code, data } = datas;
        if (code !== "0") {
          this.showMsg(message,'error');
        } else {
          this.editForm.operatoruid = data.operators.operatoruid;
          this.editForm.provinceuuid = data.provincialInformation.provinceuuid;
          this.editForm.busuuid = data.businessType.busuuid;
          this.editForm.useruuid = data.user.useruuid;
          this.editForm.fastchargetype =  data.fastchargetype+"";
          this.editForm.productCode = data.productCode;
          this.editForm.upfacevalue = data.upfacevalue;
          this.editForm.discount = data.discount;
          this.editForm.remark = data.remark;
          this.editForm.upprouuid = data.upprouuid;
          this.editForm.price = data.price;
          this.editForm.discountAmount = data.discountAmount;
          this.editForm.validity = data.validity;
          this.editForm.productName = data.productName;
          this.editForm.cityName = data.cityName;
        }
      });
    },
    async findAllCity(province) {
      let para = {
        province : province.provincialInformation ? province.provincialInformation.provincename : province
      };
      const result = await findAllCity(para);
      if(result && result.data){
        this.infoFilters = [];
        this.citys = [];
        result.data.forEach((item,index) =>{
          this.citys.push({id:index,cityName:item});
          this.infoFilters.push({id:index,cityName:item});
        })
        this.form.cityName = result.data.cityName;
      }
    },
    operatornameFormatter(row){
      return row.operators.operatorname;
    },
    provincialInformationFormatter(row){
      return row.provincialInformation.provincename;
    },
    businessTypeFormatter(row){
      return row.businessType.busname;
    },
    usernameFormatter(row){
      return row.user.username;
    },
    statusFormatter: function (row) {
      return row.status == "1" ? '正常' : row.status == "0" ? '删除' :  row.status == "2"  ? "禁用" :  '未知';
    },
    handleBatchEdit(){
      if(this.filters.operatoruid == ""){
        this.showMsg("请先选择运营商","error");
        return;
      }
      if(this.filters.provinceuuid == ""){
        this.showMsg("请先选择省份","error");
        return;
      }
      if(this.filters.busuuid == ""  ){
        this.showMsg("请先选择业务类型","error");
        return;
      }
      if(this.filters.useruuid == ""){
        this.showMsg("请先选择分销商","error");
        return;
      }
      this.setBatchProducts = [];
      this.findBatchUpProduct(this.filters.cityName);
      this.batchForm.operatoruid = this.filters.operatoruid;
      this.batchForm.provinceuuid = this.filters.provinceuuid;
      this.batchForm.busuuid = this.filters.busuuid;
      this.batchForm.useruuid = this.filters.useruuid;
      this.changeOperator(this.filters.operatoruid);
      this.batchFormVisible = true;
    },
    async exportUpProduct(){
      let para = {
        provinceuuid: this.filters.provinceuuid == "0" ? "" :this.filters.provinceuuid  ,
        operatoruid:this.filters.operatoruid == "0" ? "" :this.filters.operatoruid ,
        busuuid:this.filters.busuuid == "0" ? "" :this.filters.busuuid ,
        useruuid:this.filters.useruuid == "0" ? "" :this.filters.useruuid ,
        productCode:this.filters.productCode ,
        fastchargetype:'',
        upfacevalue:''
      };
      const result = await exportUpProduct(para);
      if(result && result.data){
        window.open(result.data.path)
      }
    },
    selectfilter(provinceuuid){
      this.filters.cityName = "";
      const result = this.info.find(item => item.provinceuuid == provinceuuid);
      if(result){
        this.findAllCity(result.provincename)
      }
    },
    async findBatchUpProduct(cityName) {
      let para = {
        operatoruid: this.filters.operatoruid,
        provinceuuid: this.filters.provinceuuid,
        busuuid: this.filters.busuuid,
        useruuid: this.filters.useruuid,
        cityName: cityName
      }
      const results = await findBatchUpProduct(para);
      let {message, code, data} = results;
      if (code !== "0") {
        this.showMsg(message,"error");
        return;
      }
      if (data && data.length == 0) {
        this.showMsg("没有找到产品,请重新选择","error");
      } else {
        this.setBatchProducts = [];
        this.setBatchPhoneProducts = [];
        this.batchForm.channe = [];
        for (var pro in data) {
          this.batchForm.channe.push(parseInt(data[pro].upfacevalue));
          var obj = new Object();
          obj.price = data[pro].price;
          obj.upfacevalue = data[pro].upfacevalue;
          obj.discount = data[pro].discount;
          obj.discountAmount = data[pro].discountAmount;
          obj.productCode = data[pro].productCode;
          obj.productName = data[pro].productName;
          obj.upprouuid = data[pro].upprouuid;
          obj.deduct = data[pro].discount;//扣款折扣
          obj.deductAmount = data[pro].discountAmount;
          this.batchForm.unitPrice = data[pro].discount + "";
          this.batchForm.pressOrder = data[pro].pressOrder;
          this.batchForm.artificial = data[pro].artificial;
          if (cityName) {
            this.batchForm.cityName = data[pro].cityName;
          }
          this.setBatchProducts.push(obj);
          this.setBatchPhoneProducts.push(obj);
        }
        if (this.setBatchPhoneProducts != null && this.setBatchPhoneProducts.length > 0) {
          this.batchForm.discount = this.setBatchPhoneProducts[0].discount;
          //this.batchPhoneForm.deduct = this.setBatchPhoneProducts[0].deduct;
        }
      }
    },
    changeOperator:function(value){
      this.form.channe = [];
      let para = {
        operatoruid:value
      };
      findByChannel(para).then(datas =>{
        let {message, code, data} = datas;
        if (code !== "0") {
          this.$message({
            message: message,
            type: 'error'
          });
        } else {
          this.channels = data;
        }
      })
    },
    handleEnable(row){
      this.$confirm('确认更新该产品状态吗?', '提示', {
        type: 'warning',
        roundButton:true
      }).then( async () => {
        let para = {
          upprouuid:row.upprouuid,
          status : row.status == "2" ? "1" : "2",
          useruuid: this.$store.getters.useruuid
        };
        const result = await productEnable(para);
        this.resultApply(result);
      });
    },
    deleteEnable(row){
      this.$confirm('确定删除产品吗?', '提示', {
        type: 'warning',
        roundButton:true
      }).then( async () => {
        const result = await deleteUpProduct([row]);
          if (result.code == "0") {
            this.showMsg("删除成功","info");
          }
          this.resultApply(result);
      });
    },
    discountChangeAdd:function () {
      this.addProduct();
    },
    addProduct(){
      var temps = this.setProducts;
      this.setProducts = [];
      for(var cha in this.form.channe){
        for(var ch in this.channels){
          if(this.channels[ch].basePrice+"" == this.form.channe[cha]){
            if(this.form.packagetype == 1){
              var obj = new Object();
              obj.price = this.channels[ch].basePrice;
              obj.upfacevalue = this.channels[ch].flow;
              //obj.discount = (this.channels[ch].basePrice * this.form.unitPrice / this.channels[ch].basePrice).toFixed(5);
              obj.discount = this.form.unitPrice;
              obj.discountAmount = (this.channels[ch].basePrice * this.form.unitPrice ).toFixed(5);
              obj.productCode = obj.upfacevalue;
              if(this.form.provinceuuid){
                const result = this.info.find(item => { return item.provinceuuid == this.form.provinceuuid });
                if(result){
                  if(this.form.busuuid == this.busstype){
                    obj.productName = result.provincename + obj.upfacevalue+"元";
                  }else{
                    obj.productName = result.provincename + obj.upfacevalue+"元";
                  }
                }else{
                  if(this.form.busuuid == this.busstype){
                    obj.productName = obj.upfacevalue+"元";
                  }else{
                    obj.productName = obj.upfacevalue+"元";
                  }
                }
              }else{
                if(this.form.busuuid == this.busstype){
                  obj.productName = obj.upfacevalue+"元";
                }else{
                  obj.productName = obj.upfacevalue+"元";
                }
              }
              this.setProducts.push(obj);
            }else if(this.form.packagetype == 0){
              var obj = new Object();
              obj.price = this.channels[ch].basePrice;
              obj.upfacevalue = this.channels[ch].flow;
              obj.discount = this.form.unitPrice;
              obj.discountAmount = (this.channels[ch].basePrice * this.form.unitPrice ).toFixed(5);
              obj.productCode = obj.upfacevalue;
              if(this.form.provinceuuid){
                const result = this.info.find(item => { return item.provinceuuid == this.form.provinceuuid });
                if(result){
                  if(this.form.busuuid == this.busstype){
                    obj.productName = result.provincename + obj.upfacevalue+"元";
                  }else{
                    obj.productName = result.provincename + obj.upfacevalue+"元";
                  }
                }else{
                  if(this.form.busuuid == this.busstype){
                    obj.productName = obj.upfacevalue+"元";
                  }else{
                    obj.productName = obj.upfacevalue+"元";
                  }
                }
              }else{
                if(this.form.busuuid == this.busstype){
                  obj.productName = obj.upfacevalue+"元";
                }else{
                  obj.productName = obj.upfacevalue+"元";
                }
              }
              this.setProducts.push(obj);
            }
          }
        }
      }
    },
    selectCity(provinceuuid){
      const result = this.info.find(item => item.provinceuuid == provinceuuid);
      if(result){
        this.findAllCity(result.provincename)
      }
      if(provinceuuid ){
        // if(this.setBatchProducts){
        //   const result = this.info.find(item => { return item.provinceuuid ==  provinceuuid});
        //   if(result){
        //     this.setBatchProducts.forEach( item =>{
        //       const face = item.productName.replace(/[^0-9]/ig,"");
        //       item.productName = result.provincename + face + "元话费";
        //     });
        //   }
        // }
        // if(this.setProducts){
        //   const result = this.info.find(item => { return item.provinceuuid ==  provinceuuid});
        //   if(result){
        //     this.setProducts.forEach( item =>{
        //       const face = item.productName.replace(/[^0-9]/ig,"");
        //       item.productName = result.provincename + face + "元话费";
        //     });
        //   }
        // }
      }
    },
    changeBatchPressOrder(form){
      console.log(form)
    },
    changeBatchArtificial(form){
      console.log(form)
    },
    addUpProduct: function () {
      if(this.setProducts != null && this.setProducts.length > 0){
        for(var i = 0 ; i < this.setProducts.length ; i++){
          if(!this.setProducts[i].productName || !this.setProducts[i].productCode){
            this.showMsg("产品名称错误,请检查","error");
            return;
          }
        }
        this.$confirm('确认提交吗？', '提示', {roundButton:true}).then( async () => {
          let para = Object.assign({}, this.form);
          para.products = this.setProducts;
          para.fastchargetype = 1;
          const result = await addBatchUpProduct(para);
          this.resultApply(result);
          if(result.code == "0"){
            this.showMsg("添加成功","success");
          }
        });
      }else{
        this.showMsg("请输入产品明细","error");
      }
    },
    handleCheckedChange(value){
      this.addProduct();
    },
    upfacevalueprice(row, column){
      return  row.price+"元";
    },
    upfacevalueProduct(row, column){
      return  this.form.busuuid == undefined ? row.upfacevalue : this.form.busuuid == this.busstype ? row.upfacevalue+"元" : row.upfacevalue+"元";
    },
    upfacevalueProductBatch(row, column){
      return  this.batchForm.busuuid == undefined ? row.upfacevalue : this.batchForm.busuuid == this.busstype ? row.upfacevalue+"元" : row.upfacevalue+"元";
    },
    handleDataInsertBatch(){
      this.dialogTitle = "批量新增供货商产品";
      this.handleDataInsert();
    },
    selsChange: function (sels) {
      this.sels = sels;
    },
    discountChangeEdit () {
      this.editForm.discountAmount = (this.editForm.discount * this.editForm.price).toFixed(5);
    },
    editSubmit () {
      this.$refs.editForm.validate((valid) => {
        if (valid) {
          this.$confirm('确认提交吗？', '提示', {roundButton:true}).then(() => {
            let para = Object.assign({}, this.editForm);
            if(para.discount){
            }
            updateUpProduct(para).then((datas) => {
               this.search();
              this.editFormVisible = false;
            }).catch(e =>{
            });
          });
        }
      });
    },
    discountBatchChangeAdd(){
      this.editProduct();
    },
    editProduct(){
      var temps = this.setBatchProducts;
      this.setBatchProducts = [];
      for(var cha in this.batchForm.channe){
        for(var ch in this.channels){
          if(this.channels[ch].basePrice+"" == this.batchForm.channe[cha]){
            var obj = new Object();
            obj.price = this.channels[ch].basePrice;
            obj.upfacevalue = this.channels[ch].flow;
            obj.discount = (this.channels[ch].flow * this.batchForm.unitPrice / this.channels[ch].basePrice).toFixed(5);
            obj.discountAmount = (this.channels[ch].flow * this.batchForm.unitPrice ).toFixed(5);
            const code = temps.find(item => {return item.price == this.channels[ch].basePrice});
            obj.productCode = code ? code.productCode : "";
            if(this.batchForm.provinceuuid){
              const result = this.info.find(item => { return item.provinceuuid == this.batchForm.provinceuuid });
              if(result){
                if(this.batchForm.busuuid == this.busstype){
                  obj.productName = result.provincename + obj.upfacevalue+"元";
                }else{
                  obj.productName = result.provincename + obj.upfacevalue+"元";
                }
              }else{
                if(this.batchForm.busuuid == this.busstype){
                  obj.productName = obj.upfacevalue+"元";
                }else{
                  obj.productName = obj.upfacevalue+"元";
                }
              }
            }else{
              if(this.batchForm.busuuid == this.busstype){
                obj.productName = obj.upfacevalue+"元";
              }else{
                obj.productName = obj.upfacevalue+"元";
              }
            }
            if(temps.length > 0){
              const result = temps.find(item =>{ return item.upfacevalue == obj.upfacevalue});
              if(result){
                obj.upprouuid = result.upprouuid;
              }
            }else{
              obj.upprouuid = this.channels[ch].upprouuid;
            }
            this.setBatchProducts.push(obj);
          }
        }
      }
    },
    updateProductName(row){

    },
    handleBatchCheckedChange(){
      this.editProduct();
    },
    editBatchUpProduct(){
      if(this.setBatchProducts != null && this.setBatchProducts.length > 0 ){
        for(var i = 0 ; i < this.setBatchProducts.length ; i++){
          if(!this.setBatchProducts[i].productName || !this.setBatchProducts[i].productCode){
            this.$message({
              message: "产品编码错误,请检查,请输入上游提供的产品编码,如没有课填入对应的面值",
              type: 'error'
            });
            return;
          }
        }
        this.$refs.batchForm.validate((valid) => {
          if (valid) {
            this.$confirm('确认提交吗？', '提示', {roundButton:true}).then(() => {
              let para = Object.assign({}, this.batchForm);
              para.products = this.setBatchProducts;
              editBatchUpProduct(para).then((datas) => {
                this.resultSuccess(datas)
                this.batchFormVisible = false;
              });
            });
          }
        });
      }else{
        this.showMsg("请输入产品明细","error");
      }
    },
    timerPrice(){
      if(this.filters.operatoruid == ""){
        this.showMsg("请先选择运营商","error");
        return;
      }
      if(this.filters.provinceuuid == ""){
        this.showMsg("请先选择省份","error");
        return;
      }

      if(this.filters.busuuid == ""){
        this.showMsg("请先选择业务类型","error");
        return;
      }

      if(this.filters.useruuid == ""){
        this.showMsg("请先选择供货商","error");
        return;
      }
      this.matchBatchForm.operatoruid = this.filters.operatoruid;
      this.matchBatchForm.provinceuuid = this.filters.provinceuuid;
      this.matchBatchForm.busuuid = this.filters.busuuid;
      this.matchBatchForm.useruuid = this.filters.useruuid;
      this.matchBatchForm.upfacevalue = this.filters.upfacevalue;
      this.matchFormBatchLoading = true;
      console.log(this.matchBatchForm)
      this.upProductBatch();
    },
    handleCurrentChangeMatchBatchTimer: function (val) {
      this.startMatchBatchTimer = val - 1;
      this.upProductBatch();
    },
    handleSizeChangeMatchBatchTimer: function (val) {
      this.pageSizeMatchBatchTimer = val;
      this.upProductBatch();
    },
    upProductBatch(){
      let para = {
        start: this.startMatchBatchTimer,
        pageSize: this.pageSizeMatchBatchTimer,
        provinceuuid:this.filters.provinceuuid == "0" ? "" :this.filters.provinceuuid ,
        operatoruid:this.filters.operatoruid == "0" ? "" :this.filters.operatoruid ,
        busuuid:this.filters.busuuid == "0" ? "" :this.filters.busuuid ,
        useruuid:this.filters.useruuid == "0" ? "" :this.filters.useruuid ,
        productCode:this.filters.productCode ,
        fastchargetype:'',
        upfacevalue:this.filters.upfacevalue,
        validity:this.filters.validity == "0" ? "" :this.filters.validity,
        cityName:this.filters.cityName,
        status: this.filters.status == "0" ? "" :this.filters.status
      };
      this.searchOptions = para;
      findPageProduct(para).then((datas) => {
        let {message, code, data} = datas;
        if (code !== "0") {
          this.showMsg(message,'error')
        } else if(data && data.result) {
          this.upproductsBatch = data.result;
          this.totalMatchBatch = data.totalCount;
          //检查所有产品折扣是否相同
          if(this.checkProductDiscount(this.upproductsBatch)){
            this.showMsg("当前选中产品折扣不相同，请注意检查",'info')
          };
        }
      });
    },
    handleSelectionChangeBatchTimer(sels){
      this.selsBatchTimer = sels;
      if(sels && sels.length > 0 && !this.matchBatchForm.beforediscount ){
        this.matchBatchForm.beforediscount = sels[0].discount;
      }
      this.showMsg("当前已经选择"+sels.length+"个产品","info")
    },
    saveBatchPrice(){
      if(this.matchBatchForm.operatoruid == ""){
        this.showMsg("请先选择运营商","error")
        return;
      }
      if(this.matchBatchForm.provinceuuid == ""){
        this.showMsg("请先选择省份","error")
        return;
      }
      if(this.matchBatchForm.busuuid == ""){
        this.showMsg("请先选择业务类型","error")
        return;
      }
      if(this.matchBatchForm.useruuid == ""){
        this.showMsg("请先选择供货商","error")
        return;
      }
      if(this.selsBatchTimer.length == 0){
        this.showMsg("请选择产品","error")
        return;
      }
      if(!this.matchBatchForm.executeTime){
        this.showMsg("执行时间必填,请选择向前时间点执行","error")
        return;
      }

      if(this.checkProductDiscount(this.selsBatchTimer)){
        this.$confirm('产品折扣有差异，确定保存吗?', '提示', {
          type: 'warning',
          roundButton:true
        }).then(() => {
          this.saveTimer(this.matchBatchForm,this.selsBatchTimer);
        }).catch(() => {

        });
      }else{
        this.saveTimer(this.matchBatchForm,this.selsBatchTimer);
      }
    },
    saveTimer(form,batchTimer){
      if(parseFloat(this.matchBatchForm.beforediscount) == parseFloat(this.matchBatchForm.afterdiscount)){
        this.showMsg("调价前和调价后折扣相同,不需要调价,请核实","error")
        return;
      }
      //取运营商 业务类型 分销商 省份 中文名称
      form.busname = this.bus.find(item =>{ return item.busuuid == form.busuuid; }).busname;
      form.operator = this.operator.find(item =>{ return item.operatoruid == form.operatoruid; }).operatorname;
      form.province = this.info.find(item =>{ return item.provinceuuid == form.provinceuuid}).provincename;
      //计算供货商名称
      let name = this.usersUp.find(item => {return item.user.useruuid == form.useruuid }).user.username+",";
      form.upName = name.substring(0,name.lastIndexOf(","));

      form.executeTime = (form.executeTime == "" || form.executeTime == undefined) ? "" : moment(form.executeTime,"YYYY-MM-DD HH:mm:ss").format('YYYY-MM-DD HH:mm:ss')
      form.batchTimer = batchTimer;

      batchProductTimerUp(form).then(datas => {
        let {message, code, data} = datas;
        if (code !== "0") {
          this.showMsg(message,"error")
        } else {
          this.showMsg("保存成功,可进入调价列表查看","success")
          this.matchFormBatchLoading = false;
        }
      });
    },
    batchTimerPriceInput(){
      if(this.upproductsBatch && this.upproductsBatch.length > 0){
        this.upproductsBatch.forEach(obj =>{
          obj.discount = (obj.price * this.matchBatchForm.afterdiscount / obj.price).toFixed(5);
          obj.discountAmount = (obj.price * this.matchBatchForm.afterdiscount ).toFixed(5);
        });
      }
    },
    productType: function (row, column) {
      return (row.businessType.busname == "手机") ? (row.upfacevalue + '权益') : ( row.businessType.busname == "固话") ?  (row.upfacevalue + '权益') :(row.upfacevalue + '元');
    },
    status (row, column) {
      return row.status == "1" ? '正常' : row.status == "0" ? '删除' : row.status == "2" ? "禁用" : '未知';
    },
    checkProductDiscount(products){
      if(products && products.length > 0){
        const pro = products[0];
        if(!this.matchBatchForm.beforediscount){
          this.matchBatchForm.beforediscount = pro.discount;
        }
        const result = products.find(item =>{
          return item.discount != pro.discount;
        })
        if(result){
          return true;
        }
        return false;
      }
    },
  },
  mounted() {
    this.findOpeProBusShop();
    this.findAllUpShopInfo();
    this.findAllChannel();
  }
}
</script>
